/**
 * Created with IntelliJ IDEA.
 * User: user
 * Date: 22.03.13
 * Time: 16:47
 * To change this template use File | Settings | File Templates.
 */
public class MyComparableObject implements Comparable<MyComparableObject> {
    private String name;
    private int num;

    public MyComparableObject(String name, int num) {
        this.name = name;
        this.num = num;
    }

    @Override
    public int compareTo(MyComparableObject o) {
        int result = name.compareTo(o.name);
        if(result != 0) {
            return result;
        }

        result = num - o.num;
        if(result != 0) {
            return (int) result / Math.abs( result );
        }
        return 0;
    }

    @Override
    public String toString() {
        return name + " " + num;
    }
}
